import ipc from './ipc/index.js'
import axios from 'axios'
const api = axios
let prefix = ''
if (api === axios) {
  prefix = 'http://127.0.0.1:7001/'
}

export default async function (method, url, params, contentType) {
  const request = {
    method: method,
    url: prefix + url,
    data: params
  }
  if (contentType === 'json') {
    request.contentType = 'application/json'
  }
  const response = await api(request)
  return response
}

// //正常
// const successStatus = 200
// //系统错误
// const sysErrorStatus = 500
// //业务错误
// const bizErrorStatus = 502

// //本地联调地址
// const baseURLTest = '/api/test/admin'
// //发布地址
// const baseUrlProd = '/api/test/admin'
// //IPC地址
// const baseUrlIpc = ''

// export default function (method, url, params, contentType) {
//   const request = {
//     method: method,
//     baseURL: '',
//     url: url,
//     data: params,
//     headers: ''
//   }
//   if (contentType === 'json') {
//     request.contentType = 'application/json'
//   }
//   return api(request)
// }

// 支持async/await用法
// async function getUser() {
//   try {
//     const response = await axios.post(url[, data[, config]])
//     console.log(response);
//   } catch (error) {
//     console.error(error);
//   }
// }